/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package models;
import java.util.*;
import javax.persistence.*;
import play.data.format.*;
import play.data.validation.*; 

import play.db.jpa.*;

@Entity
public class Sorteo {
    @Id
    
    @Constraints.Required
    public Integer codSorteo;
    
    public String nomSorteo;
    public String metodoSorteo;
    public String estado;
    
    @Formats.DateTime(pattern="yyyy-MM-dd")
    public Date fechaIniRegParticipante;
    @Formats.DateTime(pattern="yyyy-MM-dd")
    public Date fechaFinRegParticipante;
    @Formats.DateTime(pattern="yyyy-MM-dd")
    public Date fechaSorteo;
    
    public static Sorteo findById(Integer codSorteo) {
    return JPA.em().find(Sorteo.class, codSorteo);
    }
    
    public void update(Integer codSorteo) {
    this.codSorteo= codSorteo;
    JPA.em().merge(this);
    }
    
    public void save() {
    System.out.println("Grabando nuevo sorteo ...");
    JPA.em().persist(this);
    }
    
    public void delete() {
    JPA.em().remove(this);
    } 
    
    public static Page page(){
            List<Sorteo> sorteos =  JPA.em().createQuery("from Sorteo").getResultList();
            return new Page(sorteos);
    }
         
       
        public static class Page{
            private final List<Sorteo> list;
            
            public Page(List<Sorteo> data){
                this.list = data;
            }    
            public  List<Sorteo> getList(){
                return list;
                
            }
                    
        }
        

}